#include <stdio.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define PCSPKR_EVENT_PATH "/dev/input/event15"

int main(int argc,char * argv[])
{
	unsigned int val;
	int fd = 0;
	struct input_event ev;
	
	ev.type = EV_SND;

	if (argc != 2) {
	      printf("Usage:%s value\n    20<value<32767\n",argv[0]);
	      return 0;
	}

	fd = open(PCSPKR_EVENT_PATH, O_RDWR);
	if (fd < 0) {
		printf("Open PCSPKR failed!\n");
		return 1;
	}

	val = atoi(argv[1]);

	if (val > 20 && val < 32767) {
		ev.code = SND_TONE;
		ev.value = val;
                write(fd, &ev, sizeof(ev));
	} else {
		//when val = 0,it'll mute;other value will all set 1000
		ev.code = SND_BELL;
		ev.value = val;
		write(fd, &ev, sizeof(ev));
	}
	if (val)
	        sleep(5);

	ev.value = 0;
	write(fd, &ev, sizeof(ev));

	close(fd);

	return 0;
}
